{% extends "../base_adminlte.html" %}
{% load custom_markdown %}
{% load widget_tweaks  %}
{% load staticfiles %}
{% block content %}
<div class="content-wrapper">
  <!-- Content Header (Page header) -->
    <div class="content-header">
    </div>
  <section class="content">
   <form action="" role="search" method="get">
       <div class="input-group col-md-12">
        {% with form=filter.form %}
          {% for field in form.visible_fields %}
            <div class="form-group col-sm-4 col-md-4">
                {{ field.label_tag }}
                  {% render_field field %}
            </div>
           {% endfor %}
        {% endwith %}
        </div>
                       <button  type="submit" class="btn btn-primary" id="btn_search" data-toggle="modal"
                     data-target="#addModal" >查询</button>
   {% if perms.myscheduler.Scheduler_manage %}
                       <button  type="button" class="btn btn-primary" id="btn_add" data-toggle="modal"
                     data-target="#addModal" onclick="location='{% url 'SchedulerJobAdd' %}'">新增</button>
   {% endif %}

      </form>
      <table class="table table-bordered" id="jobtable">
          <tr style="font-weight: bold; background-color: #3c8dbc80;">
             <td align="center" style="white-space:nowrap;">ID</td>
             <td align="center" style="white-space:nowrap;">任务名称</td>
             <td align="center" style="white-space:nowrap;">任务类型</td>
             <td align="center" style="white-space:nowrap;">创建者</td>
             <td align="center" style="white-space:nowrap;">任务参数</td>
             <td align="center" style="white-space:nowrap;">执行方案</td>
             <td align="center" style="white-space:nowrap;">执行计划</td>
             <td align="center" style="white-space:nowrap;">开始时间</td>
             <td align="center" style="white-space:nowrap;">结束时间</td>
             <td align="center" style="white-space:nowrap;">任务状态</td>
             <td align="center" style="white-space:nowrap;">操作</td>
          </tr>
        {% for t in page_obj %}
        <tr>
             <td style="white-space:nowrap;vertical-align:middle;">{{ t.id }}</td>
             <td style="white-space:nowrap;vertical-align:middle;">{{ t.JobName }}</td>
             <td style="white-space:nowrap;vertical-align:middle;">{{ t.Jobtpye }}</td>
             <td style="white-space:nowrap;vertical-align:middle;">{{ t.Jobowner }}</td>
            <td style="vertical-align:middle;"><p style="word-break:break-all; max-width: 250px">{{ t.Jobargs }}</p></td>
             <td style="white-space:nowrap;vertical-align:middle;">
                 {% if t.plan == 1 %}
                     执行一次
                 {% elif t.plan == 2 %}
                     间隔执行
                 {% else %}
                     cron执行
                 {% endif %}
             </td>
              <td style="vertical-align:middle;">
                  {% if t.plan == 1 %}
                    {{ t.plantime }}
                  {% elif t.plan == 3 %}
                    {{ t.crontime }}
                  {% else %}
                    {{ t.intervals }} 秒
                  {% endif %}
              </td>
             <td style="vertical-align:middle;">{{ t.starttime }}</td>
             <td style="white-space:nowrap;vertical-align:middle;">{{ t.endtime }}</td>
             <td style="white-space:nowrap;vertical-align:middle;">
                 {% if perms.myscheduler.Scheduler_manage %}
                 <input type="checkbox" name="my-checkbox" checked data-bootstrap-switch id="{{ t.id }}" value="{{ t.Jobstatus }}">
                 {% else %}
                 <input type="checkbox" name="my-checkbox" checked data-bootstrap-switch id="{{ t.id }}" value="{{ t.Jobstatus }}" readonly="readonly">
                 {% endif %}
             </td>
               <td style="white-space:nowrap;vertical-align:middle;">
                   {% if perms.myscheduler.Scheduler_manage %}
                  <button type="button" class="btn btn-danger btn-xs" onclick="del({{ t.id }});">删除</button>
                   {% endif %}
              </td>

        </tr>
        {% endfor %}
      </table>
<div  style="float:right;height: 200px;font-size:15px">
                 {#  #总条数#}
            <div  style="width: 90px;height: 50px;float:left;margin: 10px 0 0 1px">总记录<label>{{ filter.qs|length }}</label>条</div>
                {#  #总页码#}
            <div  style="width: 60px;height: 50px;float:left;margin: 10px 0 0 1px">共<label>{{ total }}</label>页</div>
                {#  #当前页码#}
               {# #首页#}

               <div  style="width: 30px;height: 50px;float:left;margin: 10px 0 0 1px">
                        <p><a href="?{% param_replace page=1 %}">首页</a></p>
               </div>
                {# #前一页#}
                <div style="width: 30px;height: 50px;float:left;margin: 10px 0 0 5px">
                   {% if page_obj.has_previous %}
                     <p><a href="?{% param_replace page=page_obj.previous_page_number %}">{{ page_obj.previous_page_number }}</a> </p>
                    {% endif %}
               </div>
                {##当前页页码#}
               <div  style="width: 30px;height: 50px;float:left;margin: 10px 0 0 1px">
                   <p> {{ page_obj.number }}</p>

               </div>
                {# #后一页#}
               <div style="width: 30px;height: 50px;float:left;margin: 10px 0 0 1px">
               {% if page_obj.has_next %}
                   <p><a class="page-link" href="?{% param_replace page=page_obj.next_page_number %}">{{ page_obj.next_page_number }}</a></p>
                {% endif %}
               </div>
                {##尾页#}
                 <div  style="width: 30px;height: 50px;float:left;margin: 10px 0 0 1px">
                        <p><a href="?{% param_replace page=total %}">尾页</a> </p>
               </div>
  </div>
  </section>
</div>
<style type="text/css">
  td {
    background-color: #dadbdb80;
  }
</style>
{% endblock %}

{% block scriptcontent %}
<!-- Bootstrap Switch -->
<script src="/static/adminlte/plugins/bootstrap-switch/js/bootstrap-switch.min.js"></script>
<script>
    $(function () {
        $("input[data-bootstrap-switch]").each(function(){
            var jobstatus = $(this).val()
            var jstatus = true
            if (jobstatus == 1){
                jstatus = false
            }
            var jdisable = false
            if (jobstatus == 2){
                jdisable = true
            }
          $(this).bootstrapSwitch( {
            onText:"暂停",
            offText:"继续",
            onColor:"success",
            offColor:"info",
            size:"small",
            state:jstatus,
            disabled:jdisable,
            onSwitchChange:function(event,state){
              if(state==false){
                    $.ajax({
                    url: '/myscheduler/schedulerjobpause',
                    data: { "jobid": $(this).attr('id'),
                    },
                    type: 'GET',
                    dataType: 'json',
                    success:function (data){
                        alert(data)
                     },
                });
                 }else{
                    $.ajax({
                        url: '/myscheduler/schedulerjobresume',
                        data: { "jobid": $(this).attr('id'),
                        },
                        type: 'GET',
                        dataType: 'json',
                        success:function (data){
                            alert(data)
                         },
                    });
                 }
             }
          });
        })
    })
    function del(a){
             if(confirm("确实要删除吗?")){
                 alert("已经删除！");
                 location='{% url 'SchedulerJobDel' %}?id='+a+''
            }else{
                alert("已经取消了删除操作");
             }
    }
</script>
{% endblock %}
